package org.dromara.bykt.utils;

import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

public class MessageUtils {

	private static MessageSource messageSource;
	static {
		messageSource = (MessageSource) SpringUtil.getBean("messageSource");
	}

	public static String getMessage(int code) {
		return getMessage(code, new String[0]);
	}

	public static String getMessage(String key) {
		return getMessage(key, new String[0]);
	}

	public static String getMessage(int code, String... params) {
		return messageSource.getMessage(code + "", params, LocaleContextHolder.getLocale());
	}

	public static String getMessage(String key, String... params) {
		return messageSource.getMessage(key, params, LocaleContextHolder.getLocale());
	}

	public static String getMessage(String key, Locale locale, String... params) {
		return messageSource.getMessage(key, params, locale);
	}

}
